package com.cs.controller;

import com.cs.domain.Announcement;
import com.cs.dto.AnnouncementPageQueryDTO;
import com.cs.result.PageResult;
import com.cs.result.Result;
import com.cs.service.AnnouncementService;
import com.cs.service.impl.AnnouncementServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/announcement")
@Api(tags = "通知操作")
@CrossOrigin//解决跨域问题
@Slf4j
public class AnnouncementController {
    @Autowired
    AnnouncementService announcementService = new AnnouncementServiceImpl();
    /**
     * 分页查询通知
     * @param announcementPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询通知")
    public Result<PageResult> page(AnnouncementPageQueryDTO announcementPageQueryDTO){
        log.info("分页查询通知: {}", announcementPageQueryDTO);
        PageResult pageResult = announcementService.pageQuery(announcementPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查询所有通知
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查询所有通知")
    public Result<List<Announcement>> list(){
        return Result.success(announcementService.list());
    }
}
